package com.yule.runner;

import com.yule.model.TgctSaleStation;
import com.yule.service.TgctSaleStationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author gjl
 * 2017/9/1
 */
@Component
@Order(value = 1)
public class SaleStationsRunner implements CommandLineRunner {

    private static Logger logger = LoggerFactory.getLogger(SaleStationsRunner.class);

    @Autowired
    private TgctSaleStationService tgctSaleStationService;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public void run(String... arg0) throws Exception {
        List<TgctSaleStation> list = tgctSaleStationService.querySaleStationsByExample(null);
        for (TgctSaleStation tgctSaleStation : list) {
            stringRedisTemplate.opsForValue().set("saleStationId_" + tgctSaleStation.getDealercompanyid(),
                    tgctSaleStation.getDealername());
        }
        logger.info("============= 超市零售商数据缓存加载完成 =============");
    }

}
